package com.ict.web.controller.yzq;


import java.util.List;
import com.ict.web.domain.PerformanceIndicators;
import com.ict.web.dto.InsertPerformanceDto;
import com.ict.web.dto.QueryPerformanceDto;
import com.ict.web.dto.UpdatePerformanceDto;
import com.ict.web.mapper.PerformanceIndicatorsMapper;
import com.ict.web.service.IPerformanceService;
import com.ict.web.vo.PerformanceListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ict.common.annotation.Log;
import com.ict.common.core.controller.BaseController;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.enums.BusinessType;
import com.ict.common.core.page.TableDataInfo;

/**
 * 绩效Controller
 *
 * @author xss
 * @date 2022-02-15
 */
@Api(tags = "绩效")
@RestController
@RequestMapping("/web/performance")
public class PerformanceController extends BaseController
{
   @Autowired
   private IPerformanceService performanceService;
   @Autowired
   private PerformanceIndicatorsMapper indicatorsMapper;

    /**
     * 查询绩效列表
     */
    @ApiOperation("查询绩效列表")
    @Transactional(rollbackFor = Exception.class)
    @GetMapping("/list")
    public TableDataInfo list(QueryPerformanceDto queryDto)
    {
        startPage();
        //查询所有绩效列表
        List<PerformanceListVo> performanceList = performanceService.selectPerformanceList(queryDto);
        return getDataTable(performanceList);
    }

    /**
     * 获取绩效详细信息
     */
    @ApiOperation("查询绩效详情")
    //@PreAuthorize("@ss.hasPermi('web:performance:query')")
    @GetMapping(value = "/{perId}")
    public AjaxResult getInfo(@PathVariable("perId") Long perId)
    {
        return AjaxResult.success(performanceService.selectPerformanceByPerId(perId));
    }

    /**
     * 启用
     * @param perId
     * @return
     */
//    @PreAuthorize("@ss.hasPermi('web:performance:enable')")
    @ApiOperation("绩效配置启用")
    @PostMapping("/enable/{perId}")
    public AjaxResult enable(@PathVariable("perId") Long perId){
        performanceService.enable(perId);
       return AjaxResult.success();
    }

//    @PreAuthorize("@ss.hasPermi('web:performance:disContinue')")
    @ApiOperation("绩效配置停止使用")
    @PostMapping("disContinue/{perId}")
    public AjaxResult disContinue(@PathVariable("perId") Long perId){
        performanceService.disContinue(perId);
        return AjaxResult.success();
    }

    /**
     * 新增绩效
     */
    @ApiOperation("新增绩效信息")
//    @PreAuthorize("@ss.hasPermi('web:performance:add')")
    @Log(title = "绩效", businessType = BusinessType.INSERT)
    @PostMapping("/addSave")
    public String add(@Validated @RequestBody InsertPerformanceDto addDto)
    {
        return performanceService.insertPerformance(addDto);
    }

    /**x
     * 修改绩效
     */
    @ApiOperation("修改绩效信息")
//    @PreAuthorize("@ss.hasPermi('web:performance:edit')")
    @Log(title = "绩效", businessType = BusinessType.UPDATE)
    @PutMapping("/editSave/{perId}")
    public AjaxResult edit(@PathVariable("perId") Long perId, @RequestBody UpdatePerformanceDto updateDto)
    {
        performanceService.updatePerformance(perId,updateDto);
        return AjaxResult.success();
    }

    /**
     * 删除绩效
     */
    @ApiOperation("删除绩效信息")
//    @PreAuthorize("@ss.hasPermi('web:performance:remove')")
    @Log(title = "绩效", businessType = BusinessType.DELETE)
	@DeleteMapping("/{perId}")
    public AjaxResult remove(@PathVariable Long perId)
    {
        return toAjax(performanceService.deletePerformanceByPerId(perId));
    }

    @GetMapping("/gettt")
    public AjaxResult gettt()
    {
        List<PerformanceIndicators> performanceIndicators = performanceService.selectValidPerformanceRule();
        return AjaxResult.success(performanceIndicators);
    }
}
